package net.homeftp.heimo.ui;

import net.homeftp.heimo.R;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.view.LayoutInflater;
import android.view.View;

public class AboutDialog {
	private AlertDialog about = null;
	private Context ctx = null;

	public AboutDialog(Context ctx) {
		init(ctx);
	}

	private void init(Context ctx) {
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

		String versionName = "0.0.0";
		try {
			PackageInfo pinfo;
			pinfo = ctx.getPackageManager().getPackageInfo(
					ctx.getPackageName(), 0);
			// versionNumber = pinfo.versionCode;
			versionName = pinfo.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

		builder.setTitle(R.string.app_name);
		builder.setCancelable(true);
		builder.setIcon(R.drawable.ic_launcher);
		builder.setMessage("Wedding Widget,\nCount Down For Your Big Day!\nProduced by Thinkinghead\nVersion: "
				+ versionName);
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		});

		LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(ctx.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.dialog_adview_layout, null);
		builder.setView(layout);

		about = builder.create();
	}

	public void show() {
		if (about == null) {
			init(ctx);
		}
		about.show();
	}

}